package com.itheima.advice;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/*
*
* 这个类承载着我们如何对已有的业务功能进行增强的逻辑
*
* */
@Aspect
@Component
public class MyAspect {

    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object totalTime(ProceedingJoinPoint pjp) throws Throwable {
        long t1 = System.currentTimeMillis();
        Object o = pjp.proceed();
        long t2 = System.currentTimeMillis();
        long l = t2 - t1;
        System.out.println(pjp.getSignature().getDeclaringTypeName()+"类中的"+pjp.getSignature().getName()
        +"方法耗时:"+l+"毫秒..........................................");
        return o;
    }

    @After("execution(* com.itheima.service.impl.DeptServiceImpl2.select*(..))")
    public void after() {
        System.out.println("after.............");
    }

    @After("@annotation(com.itheima.anno.MyBj)")
    public void after2() {
        System.out.println("使用自定义的注解，使用注解形式的表达式.............");
    }
}
